home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / misc / pclta-1.000 / pclta-1 / hostappl / ldvpclta.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-27  |  2.7 KB  |  110 lines

  1. /***************************************************************************/
  2. /*                                                                         */
  3. /*                Copyright (1995)    FASTEC GmbH                          */
  4. /*                                                                         */
  5. /***************************************************************************/
  6. /*
  7.     Dateiname : ldvslta.h
  8.     Kategorie : C Header Datei
  9.     Zweck     : LONTalk Treiber fuer UNIX-Platformen
  10.     Hinweis   :
  11.     Autor(en) : Miran Miksic
  12.     Status    : beta getestet
  13. */
  14. /*-------------------------------------------------------------------------*/
  15. /*
  16.         Bearbeitungsstand:
  17.         1996/05/27 15:57:42 v1.1
  18.  
  19.         RCSStand:
  20.         ldvpclta.c,v 1.1 1996/05/27 15:57:42 miksic Exp
  21. */
  22. /*-------------------------------------------------------------------------*/
  23.  
  24. #include "ldv.h"
  25. #include <errno.h>
  26. #include <unistd.h>
  27. #include <fcntl.h>
  28. #include <sys/time.h>
  29.  
  30. LDVCode
  31. ldv_open( const char *device_name, LNI *pHandle )
  32. {
  33.     LNI handle;
  34.     handle = open( device_name, O_RDWR );
  35.     if( handle < 0 )
  36.     {
  37.         switch( errno )
  38.         {
  39.             case EBUSY:
  40.             case EACCES:
  41.                 return LDV_ALREADY_OPEN;
  42.             case ENOENT:
  43.             case ENAMETOOLONG:
  44.             case ENOTDIR:
  45.                 return LDV_NOT_FOUND;
  46.             case ENODEV:
  47.                 return LDV_NO_RESOURCES;
  48.             default:
  49.                 return LDV_DEVICE_ERR;
  50.         }
  51.     }
  52.     *pHandle = handle;
  53.     return LDV_OK;
  54. }
  55.  
  56. LDVCode ldv_close( LNI handle )
  57. {
  58.     if( 0 > close( handle ) )
  59.         return LDV_INVALID_DEVICE_ID;
  60.     return LDV_OK;
  61. }
  62.  
  63. LDVCode ldv_read( LNI handle, void *pMsg, unsigned length )
  64. {
  65.     if( 0 > read( handle, pMsg, length ) )
  66.     {
  67.         switch( errno )
  68.         {
  69.             case EISDIR:
  70.             case EBADF:
  71.             case EINVAL:
  72.                 return LDV_INVALID_DEVICE_ID;
  73.             case EINTR:
  74.             case EAGAIN:
  75.                 return LDV_NO_MSG_AVAIL;
  76.             case EFAULT:
  77.                 return LDV_INVALID_BUF_LEN;
  78.             case EBUSY:
  79.                 return LDV_DEVICE_BUSY;
  80.             default:
  81.                 return LDV_DEVICE_ERR;
  82.         }
  83.     }
  84.     return LDV_OK;
  85. }
  86.  
  87. LDVCode ldv_write( LNI handle, void *pMsg, unsigned length )
  88. {
  89.     if( 0 > write( handle, pMsg, length ) )
  90.     {
  91.         switch( errno )
  92.         {
  93.             case EISDIR:
  94.             case EBADF:
  95.             case EINVAL:
  96.                 return LDV_INVALID_DEVICE_ID;
  97.             case EINTR:
  98.             case EAGAIN:
  99.                 return LDV_NO_MSG_AVAIL;
  100.             case EFAULT:
  101.                 return LDV_INVALID_BUF_LEN;
  102.             case EBUSY:
  103.                 return LDV_DEVICE_BUSY;
  104.             default:
  105.                 return LDV_DEVICE_ERR;
  106.         }
  107.     }
  108.     return LDV_OK;
  109. }
  110.